package com.yumeng.framework.core.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yumeng.common.data.enums2.JsonScene;
import com.yumeng.common.utils.JacksonUtils;
import com.yumeng.config.BaseConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * Jackson默认配置基类
 *
 * @author wxd
 * @date 2024/5/30 下午10:09
 */
public abstract class JacksonConfiguration extends BaseConfiguration {

    @Bean
    @Primary
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        JacksonUtils.initObjectMapper(objectMapper, JsonScene.SPRING);
        return objectMapper;
    }
}
